﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Text;

public partial class Ribbon_Ribbon_ColorPicker : System.Web.UI.UserControl
{
    private string _onClientClick = string.Empty;
    private bool _ShowDefaultColor = true;
    private bool _ShowDefaultPalette = true;

    /// <summary>
    /// The Javascript function to use as a callback
    /// </summary>
    public string OnClientClick
    {
        get { return this._onClientClick; }
        set { this._onClientClick = value; }
    }

    /// <summary>
    /// Defines whether the ColorPicker shows the Default Color Item on top of the control
    /// </summary>
    public bool ShowDefaultColor
    {
        get { return this._ShowDefaultColor; }
        set { this._ShowDefaultColor = value; }
    }

    /// <summary>
    /// Defines whether the ColorPicker shows the Default palette at the bottom of the control
    /// </summary>
    public bool ShowDefaultPalette
    {
        get { return this._ShowDefaultPalette; }
        set { this._ShowDefaultPalette = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.PlaceHolder_DefaultColor.Visible = _ShowDefaultColor;
        this.PlaceHolder_DefaultPalette.Visible = _ShowDefaultPalette;
    }

    /// <summary>
    /// Override the Render Method to use the good Javascript Function
    /// </summary>
    /// <param name="writer"></param>
    protected override void Render(HtmlTextWriter writer)
    {
        using (System.IO.MemoryStream msOur = new System.IO.MemoryStream())
        {
            using (System.IO.StreamWriter swOur = new System.IO.StreamWriter(msOur))
            {
                HtmlTextWriter ourWriter = new HtmlTextWriter(swOur);
                base.Render(ourWriter);
                ourWriter.Flush();
                msOur.Position = 0;
                using (System.IO.StreamReader oReader = new System.IO.StreamReader(msOur))
                {
                    string sTxt = oReader.ReadToEnd();
                    sTxt = sTxt.Replace("{ClientClick}", this._onClientClick);
                    Response.Write(sTxt);
                    oReader.Close();
                }
            }
        } 

    }
}
